package com.sq.system.controller;


import com.sq.common.web.base.TableDataInfo;
import com.sq.common.web.domain.AjaxResult;
import com.sq.system.base.BaseController;
import com.sq.system.entry.SampleSet;
import com.sq.system.service.SampleSetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * (SampleSet)表控制层
 *
 * @author makejava
 * @since 2025-03-06 16:23:30
 */
@RestController
@RequestMapping("/api/sampleSet")
public class SampleSetController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private SampleSetService sampleSetService;

    /**
     * 分页查询所有数据
     *
     * @return 所有数据
     */
    @PostMapping("/getPage")
    public TableDataInfo selectAll(@RequestBody SampleSet sampleSet) {
        startPage(sampleSet.getPageNum(), sampleSet.getPageSize());
        return getDataTable(sampleSetService.list());
    }

    @PostMapping("/getList")
    public AjaxResult selectAll() {
        return success(sampleSetService.list());
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
//    @GetMapping("{id}")
//    public R selectOne(@PathVariable Serializable id) {
//        return success(this.sampleSetService.getById(id));
//    }

    /**
     * 新增数据
     *
     * @param sampleSet 实体对象
     * @return 新增结果
     */
    @PostMapping("/insert")
    public AjaxResult insert(@RequestBody SampleSet sampleSet) {
        sampleSet.setSampleSetNumber(0);
        sampleSet.setSampleSetStatus(0);
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sampleSet.setCreateTime(sdf.format(date));
        System.out.println(sampleSet.toString());
        return AjaxResult.success(this.sampleSetService.save(sampleSet));
    }

    /**
     * 修改数据
     *
     * @param sampleSet 实体对象
     * @return 修改结果
     */
    @PutMapping
    public AjaxResult update(@RequestBody SampleSet sampleSet) {
        return success(this.sampleSetService.updateById(sampleSet));
    }


    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
//    @DeleteMapping
//    public R delete(@RequestParam("idList") List<Long> idList) {
//        return success(this.sampleSetService.removeByIds(idList));
//    }
}

